home *** CD-ROM | disk | FTP | other *** search
- #pragma implementation
- /* #Specification: modules / elf only
- Module support in linuxconf only work for ELF systems.
- */
- #ifndef LINUXCONF_AOUT
- #include <dlfcn.h>
- #endif
- #include "misc.h"
- #include "module.h"
-
- class LINUXCONF_MODULES: public ARRAY{
- /*~PROTOBEG~ LINUXCONF_MODULES */
- public:
- LINUXCONF_MODULE *getitem (int no);
- /*~PROTOEND~ LINUXCONF_MODULES */
- };
-
- PUBLIC LINUXCONF_MODULE *LINUXCONF_MODULES::getitem(int no)
- {
- return (LINUXCONF_MODULE*)ARRAY::getitem(no);
- }
-
- static LINUXCONF_MODULES modules;
-
- PUBLIC LINUXCONF_MODULE::LINUXCONF_MODULE()
- {
- modules.add (this);
- }
-
- PUBLIC LINUXCONF_MODULE::~LINUXCONF_MODULE()
- {
- modules.remove (this);
- }
-
- /*
- Let the module add its own option to one menu.
- The "context" let the module identify which dialog it is
- The module is not forced to add options to the menu.
- */
- PUBLIC VIRTUAL void LINUXCONF_MODULE::setmenu (
- DIALOG &,
- MENU_CONTEXT)
- {
- }
-
- /*
- Check if the user has selected one menu option related to this module
- Do nothing most of the time.
- */
- PUBLIC VIRTUAL void LINUXCONF_MODULE::domenu (
- MENU_CONTEXT, // context
- const char *) // key
- {
- }
-
- /*
- Check if any module has something to add to this menu
- */
- void module_setmenu (DIALOG &dia, MENU_CONTEXT context)
- {
- int n = modules.getnb();
- for (int i=0; i<n; i++) modules.getitem(i)->setmenu (dia,context);
- }
- /*
- Probe the module for some update after configuration changes.
- */
- int module_probe (
- int state, // networking level 0, 1 or 2
- // at which state are we checking
- int target) // idem, but the target of the general probe
- {
- int ret = 0;
- int n = modules.getnb();
- for (int i=0; i<n; i++){
- if (modules.getitem(i)->probe (state,target)==-1){
- ret = -1;
- break;
- }
- }
- return 0;
- }
-
- /*
- Check if any module has something to do with this menu selection.
- */
- void module_domenu (MENU_CONTEXT context, const char *key)
- {
- int n = modules.getnb();
- for (int i=0; i<n; i++) modules.getitem(i)->domenu (context,key);
- }
-
- void module_config()
- {
- }
-
- static const char MODULE[]="module";
- static const char LIST[]="list";
- void module_load ()
- {
- #ifndef LINUXCONF_AOUT
- SSTRINGS tb;
- linuxconf_getall (MODULE,LIST,tb,0);
- int n = tb.getnb();
- for (int i=0; i<n; i++){
- SSTRING *s = tb.getitem(i);
- dlopen (s->get(),RTLD_LAZY);
- }
- #endif
- }
-
-